home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "defs.h"
-
- har *progname;
- har *filename;
- ixrect *pr;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- rray2ras_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- colormap_t colormap;
- register int x, y;
- int xsize, ysize, depth;
- short *shortimage, *shortptr;
- unsigned char *charimage, *charptr;
- long *longimage, *longptr;
-
- xsize = ysize = 512;
- depth = 8;
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, "X:Y:d:")) != EOF)
- switch (gc) {
- case 'X':
- xsize = atoi(optarg);
- break;
- case 'Y':
- ysize = atoi(optarg);
- break;
- case 'd':
- depth = atoi(optarg);
- break;
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s: [-X xsize] [-Y ysize] [-d depth] [infile] [outfile]\n", progname);
-
- for (stream = 0; optind < argc; stream++, optind++)
- if (stream < 2 && strcmp(argv[optind], "-") != 0)
- if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
- error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
-
- if (depth != 8 && depth != 16 && depth != 32)
- error("Cannot read images of that depth");
-
- if ((pr = mem_create(xsize, ysize, depth)) == NULL)
- error("mem_create returned NULL");
-
- switch (depth) {
- case 8:
- charimage = (unsigned char *) malloc(sizeof(unsigned char) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- charptr = charimage;
- if (fread(charimage, sizeof(*charimage), pr->pr_size.x, stdin) != pr->pr_size.x)
- error("Error reading image data (possible file size error)");
- for (x = 0; x < pr->pr_size.x; x++)
- pr_put(pr, x, y, (char) *charptr++);
- }
- free(charimage);
- break;
- case 16:
- shortimage = (short *) malloc(sizeof(short) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- shortptr = shortimage;
- if (fread(shortimage, sizeof(*shortimage), pr->pr_size.x, stdin) != pr->pr_size.x)
- error("Error reading image data (possible file size error)");
- for (x = 0; x < pr->pr_size.x; x++)
- pr_put(pr, x, y, (short) *shortptr++);
- }
- free(shortimage);
- break;
- case 32:
- longimage = (long *) malloc(sizeof(long) * pr->pr_size.x);
- for (y = 0; y < pr->pr_size.y; y++) {
- longptr = longimage;
- if (fread(longimage, sizeof(*longimage), pr->pr_size.x, stdin) != pr->pr_size.x)
- error("Error reading image data (possible file size error)");
- for (x = 0; x < pr->pr_size.x; x++)
- pr_put(pr, x, y, (long) *longptr++);
- }
- free(longimage);
- break;
- }
- colormap.type = RMT_NONE;
- colormap.length = 0;
- pr_dump(pr, stdout, &colormap, RT_STANDARD, 0);
- }
-